package com.csdj.t309springboot.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csdj.t309springboot.entity.SignInRecord;
import com.csdj.t309springboot.entity.User;
import com.csdj.t309springboot.mapper.SignInRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 谭湛宇
 * @since 2022-01-12
 */
@Service
public class SignInRecordService extends ServiceImpl<SignInRecordMapper, SignInRecord> implements ISignInRecordService {
    @Resource
    private SignInRecordMapper signInRecordMapper;
    private Logger log = LoggerFactory.getLogger("");

    /**
     * 根据用户编号查询签到记录
     * @param userId 用户编号
     * @return user用户实体类
     */
    public SignInRecord getSignInRecordByUserId(int userId){
        QueryWrapper<SignInRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SignInRecord::getUserId,userId);
        SignInRecord signInRecord = signInRecordMapper.selectOne(queryWrapper);
        return signInRecord;
    }

    /**
     * 检查是否签到
     * @param userId
     * @return 签到记录实体类
     */
    public SignInRecord checkSignIn(int userId){
        //获取今天的日期
        LocalDate signInDate = LocalDate.now();
        log.info("signInDate="+signInDate);
        QueryWrapper<SignInRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SignInRecord::getSignInDate,signInDate).eq(SignInRecord::getUserId,userId);
        return signInRecordMapper.selectOne(queryWrapper);
    }

//    public boolean updateById(SignInRecord signInRecord){
//        return signInRecordMapper.updateById(signInRecord);
//    }

}
